package test.my.notification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
    NotificationManager mNotiManager;
    public static final int NOTI_ID = 1;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mNotiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        
        Button btn = (Button)findViewById(R.id.noti_btn);
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), "통지 실행 준비...", Toast.LENGTH_SHORT).show();
                view.postDelayed(new Runnable() {
                    public void run() {
                        Notification noti = new Notification(R.drawable.noti_icon, "통지 상태표시줄에 표시될 때 메시지-메뉴를 알려드립니다.", System.currentTimeMillis());
                        noti.defaults |= Notification.FLAG_AUTO_CANCEL;
                        
                        Intent intent = new Intent(getApplicationContext(), MenuNotiActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        
                        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
                        noti.setLatestEventInfo(getApplicationContext(), "알림 목록 - 통지 제목", "알림 목록 내용 - 메뉴 알려줄까..??", pendingIntent);
                        
                        mNotiManager.notify(NOTI_ID, noti);
                    }
                }, 5 + 1000);
            }
        });
    }
}